<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<tpl> $NCharset </tpl>" />
<link href="<tpl> $template_dir </tpl>/member/css/supply-list.css" rel="stylesheet" type="text/css" />
<link href="<tpl> $template_dir </tpl>/member/css/layout.css" rel="stylesheet" type="text/css" />
<link href="<tpl> $template_dir </tpl>/member/css/supply.css" rel="stylesheet" type="text/css" />
<tpl>include file ='../head.config.html'</tpl>
</head>
<body><tpl>include file ='../top.html'</tpl>
<div class="clear"></div>
<div id="container761">
	<div class="own_member_main add-1">
		<tpl>include file ='own_menu.html'</tpl>
		<div class="member_right">
<form action="member.php?action=update" method="post" id="modisupply" name="modisupply">
	<input type="hidden" name="pic_num" id="pic_num" value="<tpl> $supply_pic_num </tpl>"/>
	<input type="hidden" name="class_id" id="class_id" value="<tpl> $supply_array.s_class_id </tpl>"/>
    <input type="hidden" name="sid" id="sid" value="<tpl> $supply_array.s_id </tpl>" />
<table class="add-1-2" cellpadding="0" cellspacing="0" style="float:left;  display:inline;">
	<tr>
    	<th width="170" height="35" align="right"><tpl> $langSupplyTitle </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input class="input_saleproduct"  type="text" id="supplyTitle"  name="supplyTitle" maxLength=30  class="searchforminput" value="<tpl> $supply_array.s_title </tpl>"/>  
          <label style="display:none" for="supplyTitle" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
	<tr>
	 <th width="170" height="30" align="right"><tpl> $langSupplySelClass </tpl>:&nbsp;&nbsp;&nbsp;</th>
		<td class="add-pd" width="565" height="30" >
        	<div id="pc_id_originality" style="display:''"><tpl> $supply_array.s_class_name </tpl>
        	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="edit_button" value="<tpl> $langCedit </tpl>" onclick="editstate()"/>
        	</div>
		    <div id="pc_id_edit" style="display:none">
            <select name="cc1" id="cc1" style="WIDTH: 110px">
            <option value=""></option>
            <tpl> foreach item = parent from = $ProductCateArray </tpl>
            <option value="<tpl>$parent.id</tpl>||<tpl>$parent[5]</tpl>"><tpl>$parent.name</tpl></option>
            <tpl> /foreach </tpl>
            </select>
            <select name="c2" id="c2" style="WIDTH: 110px">
            </select>
            <select name="c3" id="c3" style="WIDTH: 110px">
            </select>
            <select name="c4" id="c4" style="WIDTH: 110px">
            </select>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="cancel_edit_button" value="<tpl> $langCCanceledit </tpl>" onclick="canceledit()" />
          </div>
        <label style="display:none" for="searchcate" class="wrong" metaDone="true" generated="true"></label>	
        </td>
	</tr>
    <tr>
    	<th width="170" height="30" align="right"><tpl> $langSupplySelType </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="30">
        	<input type="radio" name="radioType" value="2" <tpl> if $supply_array.s_type eq 2 </tpl>checked="checked"<tpl> /if </tpl>/>&nbsp;<tpl> $langSupplyTypeGone </tpl>
			<input type="radio" name="radioType" value="1" <tpl> if $supply_array.s_type eq 1 || $supply_array.s_type eq '' </tpl>checked="checked"<tpl> /if </tpl>/>&nbsp;<tpl> $langSupplyTypeQiu </tpl>
          </td>
    </tr>
    <tr>
    	<th width="170" height="30" align="right"><tpl> $langSupplySelQuality </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="30">
        	<input   type="radio" name="radioQuality" value="1" <tpl> if $supply_array.s_quality eq 1 || $supply_array.s_quality eq '' </tpl>checked="checked"<tpl> /if </tpl>/>&nbsp;<tpl> $langSupplyQualityOne </tpl>
			<input type="radio" name="radioQuality" value="2" <tpl> if $supply_array.s_quality eq 2 </tpl>checked="checked"<tpl> /if </tpl>/>&nbsp;<tpl> $langSupplyQualityTwo </tpl>
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right"><tpl> $langSupplyValdate </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <select name="valdate" id="valdate">
          	<option value="1" <tpl> if $supply_array.s_valdate eq 1 or $vadate eq '' </tpl> selected="selected" <tpl> /if </tpl> ><tpl> $langSupplyValdateFiveDay </tpl></option>
            <option value="2" <tpl> if $supply_array.s_valdate eq 2 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateHalfMonth </tpl></option>
            <option value="3" <tpl> if $supply_array.s_valdate eq 3 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateOneMonth </tpl></option>
            <option value="4" <tpl> if $supply_array.s_valdate eq 4 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateOneQuarter </tpl></option>
            <option value="5" <tpl> if $supply_array.s_valdate eq 5 </tpl> selected="selected" <tpl> /if </tpl>><tpl> $langSupplyValdateNone </tpl></option>
          </select>
        </td>
    </tr>
	<tr>
    	<th width="170" height="35" align="right"><tpl> $langSupplyPrice </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="s_price"  name="s_price"  class="input_saleproduct"  value="<tpl> if $supply_array.s_price_face eq '2' </tpl><tpl> $supply_array.s_price </tpl><tpl> /if </tpl>"/>
		  <tpl> $langSupplyOr </tpl>
		  <input type="checkbox" name="s_price_face" <tpl> if $supply_array.s_price_face eq '1' </tpl>checked="checked"<tpl> /if </tpl> id="s_price_face" value="1" /><label for="s_price_face"> &nbsp;<tpl> $langSupplyPriceToFace </tpl></label>
          <label style="display:none" for="s_price" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right"><tpl> $langSupplyPhone </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="phone"  name="phone"  class="input_saleproduct"  value="<tpl> $supply_array.s_phone </tpl>"/>
          <label style="display:none" for="phone" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right">Email:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="mail"  name="mail"  class="input_saleproduct"  value="<tpl> $supply_array.s_email </tpl>"/>
          <label style="display:none" for="mail" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right">QQ:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="qq"  name="qq" class="input_saleproduct"  value="<tpl> $supply_array.s_qq </tpl>"/>
          <label style="display:none" for="qq" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right">MSN:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="msn"  name="msn" class="input_saleproduct"  value="<tpl> $supply_array.s_msn </tpl>"/>
          <label style="display:none" for="msn" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right">Skype:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="skype"  name="skype"  class="input_saleproduct"  value="<tpl> $supply_array.s_skype </tpl>"/>  
          <label style="display:none" for="skype" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
    	<th width="170" height="35" align="right"><tpl> $langSupplyWangwang </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565" height="35">
       	  <input type="text" id="wangwang"  name="wangwang" class="input_saleproduct"  value="<tpl> $supply_array.s_wangwang </tpl>"/>  
          <label style="display:none" for="wangwang" class="wrong" metaDone="true" generated="true"></label> 
        </td>
    </tr>
    <tr>
        <th width="170" height="35" align="right" valign="top"><tpl> $langSupplyPicUpload </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td class="add-pd" width="565">
			<div style="width:400px">
				<input name="txtPpic"  class="searchforminput" type="file"id="txtPpic" size="40"/>
				<input type="button" class="shang" name="buttonUpload" id="buttonUpload" value="<tpl> $langSupplyUpload </tpl>" onclick="return ajaxFileUpload();" />
			</div>
			<!--图片名拼字符串，中间以'|'连接-->
            <input type="hidden" name="p_pic" id="p_pic" value="<tpl> $supply_array.s_pic </tpl>" />
            <span class="posttip" style="display:block; margin:10px 0 0; width:400px"><tpl> $langSupplyPicUploadRemark </tpl></span>
			<div id="previewImage">
				<ul id="piclist">
				<tpl> foreach item=one from=$supply_array.spic_arr </tpl>
					<li><img src=<tpl> $site_url </tpl>/<tpl> $one </tpl> /><br /><a href='javascript:;' onclick="ajaxFileDel('<tpl> $one </tpl>',this);"><tpl> $errSupplyDel </tpl></a></li>
				<tpl> /foreach </tpl>
			  	</ul>
			</div>		
			<span id="file_pic_loading" style="display:none"><img src="<tpl> $template_dir </tpl>/images/loading.gif" /></span>
		</td>
     </tr>
     <tr>
        <th width="170" align="right"><tpl> $langSupplyContent </tpl>:&nbsp;&nbsp;&nbsp;</th>
        <td width="565" height="220" valign="middle" class="add-pd">
			<textarea style=" width:554px; height:120px;"  name="Content" id="Content"><tpl> $supply_array.s_content </tpl></textarea>
            <div style=" padding-top:10px; padding-bottom:10px;"><tpl> $langSupplyContentRemark </tpl></div>
				<div style="float:right; padding-right:20px;">
            <input type="checkbox" id="anonymous" name="anonymous" value="2" <tpl> if $supply_array.s_anonymous eq 2 </tpl>checked="checked"<tpl> /if </tpl>/><label for="anonymous">&nbsp;<tpl> $langSupplyAnonymous </tpl></label>
			</div>
            <input class="input-2" name="code" type="text" id="code" size="4" maxlength="4" />
			<img src="<tpl> $site_url </tpl>/classes/libraries/code.php" onclick="this.src='<tpl> $site_url </tpl>/classes/libraries/code.php?' + Math.random()" title=" <tpl> $langSupplyCodeChange </tpl> " id="codeimage" name="codeimage" style=" vertical-align:middle" /><a href="javascript:;" onclick="document.getElementById('codeimage').src='<tpl> $site_url </tpl>/classes/libraries/code.php?' + Math.random()">&nbsp;<tpl> $langSupplyCodeChange </tpl></a>
            <label style="display:none" for="code" class="wrong" metaDone="true" generated="true"></label> 
			
      	</td>
		</tr><tr>
		<th width="170"  align="right">&nbsp;&nbsp;&nbsp;</th><td height="35" align="center"><input  type="submit" id="addsubmit"  value="<tpl> $langSupplySave </tpl>" class="shang"/></td>
      </tr>


</table>
</form>
</div>
	</div>
	<tpl> include file ='../../../../html/footer.html' </tpl>
</div>
</body>
</html>
<script>
$(function(){
	//商品类别
	tonext('#cc1');
	//表单验证
	$("#modisupply").validate({
		errorClass: "wrong",
		rules: {
			class_id: {required:true},
			supplyTitle: {required:true,minlength:2,maxlength:50},
			code: {required:true,minlength:4,maxlength:4},
			phone: {required:true,maxlength:50},
			mail: {required:true,email:true,maxlength:50},
			qq: {maxlength:11},
			msn: {email:true,maxlength:50},
			skype: {maxlength:50},
			wangwang: {maxlength:50},
			s_price:{
				required:function(){
					if($('#s_price_face').attr('checked') == false){
						return true;
					}else{
						return false;
					}
				},
				number:function(){
					if($('#s_price_face').attr('checked') == false){
						return true;
					}else{
						return false;
					}
				},
				min:function(){
					if($('#s_price_face').attr('checked') == false){
						return 0.01;
					}else{
						return false;
					}
				},
				max:function(){
					if($('#s_price_face').attr('checked') == false){
						return 999999999.99;
					}else{
						$('#s_price').val('');
						return false;
					}
				}
			}
		},
		messages: {
			class_id: {required: "<tpl> $errSupplyClassIsEmtpy </tpl>"},
			supplyTitle: {required: "<tpl> $errSupplyTitleIsEmtpy </tpl>",minlength: "<tpl> $errSupplyTitleIsTooShort </tpl>",maxlength: "<tpl> $errSupplyTitleIsTooLong </tpl>"},
			code: {required: "<tpl> $errSupplyCodeIsEmpty </tpl>",minlength: "<tpl> $errSupplyCodeIsEmpty </tpl>",maxlength: "<tpl> $errSupplyCodeIsEmpty </tpl>"},
			phone: {required:'<tpl> $errSupplyPhoneIsEmpty </tpl>',maxlength: "<tpl> $errSupplyPhoneIsTooLong </tpl>"},
			mail: {required:'<tpl> $errSupplyEmailIsEmpty </tpl>',email: "<tpl> $errSupplyEmailIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyEmailIsTooLong </tpl>"},
			qq: {maxlength: "<tpl> $errSupplyQQIsTooLong </tpl>"},
			msn: {email: "<tpl> $errSupplyMSNIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyMSNIsTooLong </tpl>"},
			skype: {maxlength: "<tpl> $errSupplySkypeIsTooLong </tpl>"},
			wangwang: {maxlength: "<tpl> $errSupplyWangwangIsTooLong </tpl>"},
			s_price:{required:"<tpl> $errSupplyPriceIsEmpty </tpl>",number:"<tpl> $errSupplyPriceIsNotNumber </tpl>",min:"<tpl> $errSupplyPriceIsMin </tpl>0.01",max:"<tpl> $errSupplyPriceIsMax </tpl>999999999.99"}
		},
		submitHandler: function() {
			document.getElementById('addsubmit').disabled;
			$.get("index.php",{action:"check_code",checkcode:$('#code').val(),random_number:Math.random()},function(data){
			if(data == '1'){
				document.getElementById('modisupply').submit();
			}else{
				alert('<tpl> $errSupplyCodeIsWrong </tpl>');
				document.getElementById('addsubmit').disabled = false;
				return false;
			}})
			return false;
		}
	});
})
function tonext(whos) {
	$(whos).change(
	function(){
		var valarray=$(this).val().split('||');
		$('#class_id').val(valarray[0]);
		if (valarray[1]=='1') {
			$(this).next().attr('disabled','true').html('<option value="" selected="selected"><tpl> $langCDataToLoading </tpl></option>');
			$.get('../../member/own_productcate.php',{action:'list',id:valarray[0]},function(data){
				DataArray = data.split("|||");var a='';for (var i = 0; i<DataArray.length-1; i++) {att=DataArray[i].split("||");id=att[0];cla=att[2];a+='<option value="'+id+'||'+cla+'">'+att[1]+((cla=='1')?' ->':'')+'</option>';};
				$(whos).next().removeAttr('disabled').html('<option value="" selected="selected"></option>'+a).nextAll().html('');
				tonext($(whos).next());
			})} else {
				$('#c4').attr('disabled','true');
				$(whos).next().html('').attr('disabled','true');
			};
	})
};
//多图片上传操作
function ajaxFileUpload()
{
	$("#file_pic_loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	//如果图片数量超过3 则返回信息，不允许添加
	if($("#pic_num").val() >= 3){
		alert("<tpl> $errSupplyImageIsBeyong </tpl>:3");
		return false;
	}
	
	$.ajaxFileUpload
	(
		{
			url:'index.php?action=pic_add',
			secureuri:false,
			fileElementId:'txtPpic',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.type) != 'undefined')
				{
					if(data.type != '0')
					{
						$("#previewImage ul").append("<li>"+"<img src=<tpl> $site_url </tpl>/"+data.message+" /><br /><a href='javascript:;' onclick=ajaxFileDel(\'"+data.message+"\',this);><tpl> $errSupplyDel </tpl></a></li>");
						if($('#p_pic').val() == ''){
							$('#p_pic').val(data.message);
						}else{
							$('#p_pic').val($('#p_pic').val()+'|'+data.message);
						}
						//图片数量+1
						$("#pic_num").val(parseInt($("#pic_num").val())+1);
					}
				}
			},
			error: function (data, status, e)
			{
				alert('<tpl> $errSupplyUploadPicIsFail </tpl>');
			}
		}
	)
	return false;
}

//删除图片 缩略图名称
function ajaxFileDel(pic_url,obj){
	$.ajax({
		url: "index.php",
		data: 'action=pic_del&pic_name='+pic_url,
		type:'post',
		dataType:"json",
		success: function(msg){
			if(msg.type == '0'){
				alert(msg.message);
			}else{
				$(obj).parents("li").remove();
				arr = $('#p_pic').val().split('|');
				for(i=0;i<arr.length;i++){
					if(arr[i] == pic_url){
						delete(arr[i]);
					}
				}
				$('#p_pic').val(arr.join('|'));
				//图片数量-1
				$("#pic_num").val(parseInt($("#pic_num").val())-1);
			}
		}
	});
	return false;
}
function editstate(){
	document.getElementById('pc_id_originality').style.display = 'none';
	document.getElementById('pc_id_edit').style.display = '';
}
function canceledit(){
	document.getElementById('pc_id_originality').style.display = '';
	document.getElementById('pc_id_edit').style.display = 'none';
	searchcate = document.getElementById('class_id').value;
	document.getElementById('class_id').value = searchcate;
}
</script>